/*
* @Author: monster
* @Date:   2017-09-19 16:35:38
* @Last Modified by:   monster
* @Last Modified time: 2017-09-22 22:44:49
*/
'use strict';
angular.module('app').directive('appPositionInfo',['$http',function($http){
	return{
		restrict: 'A',
		replace: true,
		templateUrl: 'view/template/positionInfo.html',
		scope: {
			isActive : '=',
			isLogin : '=',
			pos : '='
		},
		link: function($scope) {
			// 监控数据模块是否发生变化
     	  $scope.$watch('pos', function(newVal) {
	        if(newVal) {
	          $scope.pos.select = $scope.pos.select || false;
	          $scope.imagePath = $scope.pos.select?'image/star-active.png':'image/star.png';
	        }
	      });
	      // 定义点击星星方法
	      $scope.favorite = function() {
	        $http.post('data/favorite.json', {
	          id: $scope.pos.id,
	          select: !$scope.pos.select
	        }).success(function(resp) {
	          $scope.pos.select = !$scope.pos.select;
	          $scope.imagePath = $scope.pos.select?'image/star-active.png':'image/star.png';
	        });
	      }
	    }
  	}
}]);